package com.netty.learn.tcpdemo;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;


public class TcpClient {
	
	public static void main(String[] args) {
		try {
			Socket socket = new Socket("localhost", 8080);
			int port = socket.getLocalPort();
			System.out.println("本地使用端口号： " + port);
			
			InetAddress address = socket.getLocalAddress();
			String hostName = address.getCanonicalHostName();
			System.out.println("本地地址： " + hostName);
			
			String hostAddress = address.getHostAddress();
			System.out.println("限定域名： " + hostAddress);
			
			int desPort = socket.getPort();
			System.out.println("远端端口号： " + desPort);
			
			InetAddress inetAddress = socket.getInetAddress();
			System.out.println("远程IP： " + inetAddress);
			
			InputStream inputStream = socket.getInputStream();
			OutputStream outputStream = socket.getOutputStream();
			String hello = "how are you!";
			outputStream.write(hello.getBytes());
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

}
